var t = getApp();

Page({
    data: {
        homepageData: {},
        micuid: "",
        catelist: [],
        mainCommentShow: !1,
        maincomment: "",
        active: 0,
        catelist_1: [],
        catelist_2: [],
        catelist_3: [],
        catelist_4: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        loading: !1,
        getMoreType: 1,
        self: !1,
        stick_type: 1,
        handleTag: !1,
        unread_num: "",
        message_all: {},
        message_total: 0
    },
    onLoad: function(a) {
        a.mid && t._setMid(option.mid), a.micuid && this.setData({
            micuid: a.micuid,
            self: !0
        }), this.getHomepageData();
    },
    onReady: function() {},
    onShow: function() {
        this.getMessageData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.loading ? console.log("没有更多数据") : this.getMoreData();
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.homepageData.nickname + "的微社区",
            query: "micuid=" + this.data.micuid + "&mid=" + a
        };
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.homepageData.nickname + "的微社区",
            path: "/packageC/micro_communities/microhomepage/microhomepage?micuid=" + this.data.micuid + "&mid=" + a
        };
    },
    gotoFanList: function(t) {
        var a = t.currentTarget.dataset.actived;
        wx.navigateTo({
            url: "/packageC/micro_communities/microFanlist/microFanlist?uid=" + this.data.micuid + "&actived=" + a
        });
    },
    getHomepageData: function() {
        var a = this, e = t.getNetAddresss("plugin.micro-communities.api.user.index"), i = {};
        this.data.micuid && (i.uid = this.data.micuid), t._postNetWork({
            url: e,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    homepageData: e.data,
                    micuid: e.data.uid,
                    maincomment: e.data.signature ? e.data.signature : ""
                }), 1 == a.data.homepageData.is_own ? (a.data.getMoreType = 1, a.getClassification()) : (a.data.getMoreType = 3, 
                a.getClassification())) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    getClassification: function() {
        if (3 == this.data.active) return this.setData({
            getMoreType: 4
        }), void this.getMessageData();
        var a = this, e = t.getNetAddresss("plugin.micro-communities.api.index.getStick");
        a.pageInit();
        var i = {}, s = this.data.stick_type;
        1 == this.data.getMoreType ? (i.uid = a.data.micuid, 0 != s && 1 != s || (i.stick_type = s)) : 2 == this.data.getMoreType ? i.is_praise = 1 : 3 == this.data.getMoreType && (i.uid = a.data.micuid), 
        t._postNetWork({
            url: e,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    if (a.data.total_page = e.data.last_page, 3 == a.data.getMoreType) a.setData({
                        catelist: e.data.data
                    }); else if (1 == a.data.getMoreType) {
                        if (0 == s) return void a.setData({
                            catelist_3: e.data.data
                        });
                        a.setData({
                            catelist_1: e.data.data
                        });
                    } else 2 == a.data.getMoreType && a.setData({
                        catelist_2: e.data.data
                    });
                    console.log(a.data.catelist_3, 3), console.log(a.data.catelist_2, 2), console.log(a.data.catelist_1, 1);
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    attentionBtn: function() {
        this.data.homepageData.is_follow ? this.cancelAttention() : this.addAttention();
    },
    cancelAttention: function() {
        var a = this, e = t.getNetAddresss("plugin.micro-communities.api.user.delFollow"), i = {
            uid: this.data.micuid
        };
        t._postNetWork({
            url: e,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    "homepageData.is_follow": !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    addAttention: function() {
        var a = this, e = t.getNetAddresss("plugin.micro-communities.api.user.addFollow"), i = {
            user_id: this.data.micuid
        };
        t._postNetWork({
            url: e,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    "homepageData.is_follow": !0
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    jumpDetails: function(t) {
        var a = t.currentTarget.dataset.stickid;
        wx.navigateTo({
            url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + a
        });
    },
    pageInit: function() {
        this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0, this.data.loading = !1;
    },
    getMoreData: function() {
        var a = this, e = {}, i = this.data.stick_type;
        1 == this.data.getMoreType ? (e.uid = a.data.micuid, 0 != i && 1 != i || (e.stick_type = i)) : 2 == this.data.getMoreType ? e.is_praise = 1 : 3 == this.data.getMoreType && (e.uid = a.data.micuid), 
        a.data.isLoadMore = !1;
        var s = "";
        s = 3 == a.data.active ? t.getNetAddresss("plugin.micro-communities.api.message.index") : t.getNetAddresss("plugin.micro-communities.api.index.getStick"), 
        this.data.page >= this.data.total_page ? a.setData({
            loading: !0
        }) : (a.data.page = this.data.page + 1, e.page = this.data.page, t._postNetWork({
            url: s,
            showToastIn: !1,
            data: e,
            success: function(t) {
                var e = t.data;
                if (console.log(t), 1 != e.result) return a.data.page = a.data.page - 1, void (a.data.isLoadMore = !1);
                var s = e.data.data;
                if (4 == a.data.getMoreType && (s = e.data.stick_comment_list.data), a.setData({
                    handleTag: !1
                }), 3 == a.data.getMoreType) a.setData({
                    catelist: a.data.catelist.concat(s)
                }); else if (1 == a.data.getMoreType) {
                    if (0 == i) return void a.setData({
                        catelist_3: a.data.catelist_3.concat(s)
                    });
                    a.setData({
                        catelist_1: a.data.catelist_1.concat(s)
                    });
                } else 2 == a.data.getMoreType ? a.setData({
                    catelist_2: a.data.catelist_2.concat(s)
                }) : 4 == a.data.getMoreType && a.setData({
                    catelist_4: a.data.catelist_4.concat(s)
                });
            },
            fail: function(t) {}
        }));
    },
    introductionInp: function() {
        this.setData({
            mainCommentShow: !0
        });
    },
    subMainBtn: function() {
        if (!this.data.maincomment) return wx.showToast({
            icon: "none",
            title: "请留下你的简介吧",
            duration: 1500
        }), !1;
        var a = this, e = {}, i = t.getNetAddresss("plugin.micro-communities.api.user.upSignature");
        e.contents = this.data.maincomment, t._postNetWork({
            url: i,
            showToastIn: !1,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    "homepageData.signature": a.data.maincomment,
                    mainCommentShow: !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    maincommentinp: function(t) {
        var a = t.detail.value;
        this.setData({
            maincomment: a
        });
    },
    showClose: function() {
        this.setData({
            mainCommentShow: !1
        });
    },
    getClassificationBtn: function(t) {
        var a = t.detail.index;
        this.setData({
            active: a,
            handleTag: !0
        }), 2 == a ? (this.data.getMoreType = 2, this.getClassification()) : (this.data.getMoreType = 1, 
        0 == a ? this.setData({
            stick_type: 1
        }) : 1 == a ? this.setData({
            stick_type: 0
        }) : this.setData({
            stick_type: a
        }), this.getClassification());
    },
    link: function(a) {
        var e = this, i = a.currentTarget.dataset, s = i.stickid, o = i.type, n = "";
        i.ready && (n = i.ready), "all" == o ? t._postNetWork({
            url: t.getNetAddresss("plugin.micro-communities.api.message.change-is-read"),
            success: function(a) {
                1 == a.data.result ? (e.setData({
                    unread_num: 0
                }), t.tips(a.data.msg), e.getMessageData()) : t.tips(a.data.msg);
            }
        }) : "single" == o && t._postNetWork({
            url: t.getNetAddresss("plugin.micro-communities.api.message.change-is-read"),
            data: {
                stick_id: s
            },
            success: function(a) {
                a.data.result || 1 == n ? wx.navigateTo({
                    url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + s
                }) : t.tips(a.data.msg);
            }
        });
    },
    getMessageData: function() {
        var a = this;
        this.pageInit(), t._getNetWork({
            url: t.getNetAddresss("plugin.micro-communities.api.message.index"),
            data: {
                page: this.data.page
            },
            success: function(t) {
                if (1 == t.data.result) {
                    var e = t.data.data.stick_comment_list;
                    1 == a.data.page ? a.setData({
                        message_total: e.total,
                        page: e.current_page,
                        total_page: e.last_page,
                        unread_num: t.data.data.unread_num,
                        catelist_4: e.data
                    }) : a.setData({
                        page: e.current_page,
                        total_page: e.last_page,
                        catelist_4: a.dta.catelist_4.concat(e.data)
                    });
                }
            }
        });
    }
});